Python matplotlib绘图设置图例案例 您所在的位置:网站首页 python plot 添加图例 Python matplotlib绘图设置图例案例

Python matplotlib绘图设置图例案例

#Python matplotlib绘图设置图例案例| 来源: 网络整理| 查看: 265

目录一、语法简介二、完整代码一、语法简介plt.legend(loc=2,edgecolor='red',facecolor='green',shadow='True',fontsize=10)...

目录一、语法简介二、完整代码

一、语法简介

plt.legend(loc=2,edgecolor='red',facecolor='greenmWwSbvpf',shadow='True',fontsize=10)

edgecolor 图例边框线颜色 facecolor 图例背景色 shadow 是否添加阴影 title 图例标题 fontsize 设置字体大小

''' 设置图例位置loc参数简介 best 0 根据图标区域自动选择最合适的位置 upper right 1 右上角 upper left 2 左上角 lower left 3 左下角 lower right 4 右下角 right 5 右侧 center left 6 左侧中心 center right 7 右侧中心 lower center 8 底部中心 upper center 9 顶部中心 center 10 正中心位置 ''' http://www.cppcns.com

二、完整代码 import matplotlib.pyplot as plt import numpy as np plt.rcParams['font.sans-serif'] = ['STZhongsong'] # 指定默认字体:解决plot不能显示中文问题 plt.rcP编程客栈arams['axes.unicode_minus'] = False #用来正常显示负号 x=np.arange(8) y=np.arange(100,900,100) print(y) #建立画布 figsize,它用width和height来控制画布的宽和高 plt.figure(figsize=(8,6),dpi=90) #facecolor='red'设置画布颜色 plt.subplot(1,1,1)#建立坐标系 plt.mWwSbvpfbar(x,y,label='销售数量') #绘制柱状图 plt.xlabel("销售月份",fontsize=10,color='red',fontweight='bold',loc='center',backgroundcolor='black',labelpad=6) #显示横坐标标题 fontsize设置字体大小,color设置字的颜色,fontweight设置标签是否加粗 #loc设置标签位置(具体值有center left right) backgroundcolor设置标签的背景颜色 labelpad与轴的距离 plt.ylabel("销售数量") plt.xticks(x,['2021年1月','2021年2月','2021年3月','2021年4月','2021年5月','2021年6月','2021年7月','2021年8月',],rotation=15) plt.yticks(y,['100k','200k','300k','400k','500k','600k','700k','800k',], rotation=30,fontsize=10,color='red',fontweight='bold',backgroundcolor='black')#rotation设置刻度值倾斜角度 plt.xlim(-1,9) #设置x轴刻度值的范围 plt.ylim(0,900)#设置y轴刻度值的范围 plt.axis("on") #plt.axis("off") #关闭坐标轴 plt.legend(loc=2,edgecolor='red',facecolor='green',shadow='True',fontsize=10) #edgecolor 图例边框线颜色 facecolor 图例背景色 编程客栈shadow 是否添加阴影 title 图例标题 fontsize 设置字体大小 ''' 设置图例位置loc参数简介 best 0 根据图标区域自动选择最合适的位置 upper right 1 右上角 upper left 2 左上角 lower left 3 左下角 lower right 4 右下角 right 5 右侧 center left 6 左侧中心 center right 7 右侧中心 lower center 8 底部中心 upper center 9 顶部中心 center 10 正中心位置 ''' plt.show()

三、效果图展示

Python matplotlib绘图设置图例案例

到此这篇关于python matplotlib绘图设置图例案例的文章就介绍到这了,更多相关Python matplotlib绘图设置图例内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

本文标题: Python matplotlib绘图设置图例案例 本文地址: http://www.cppcns.com/jiaoben/python/446207.html


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有